<template>
    <div class="app-container">
        <el-form class="lookForm" :model="queryParams" ref="queryForm" size="mini" :inline="true" label-width="140px">
            <el-form-item label="学号" prop="stuNo">
                <el-input v-model="queryParams.stuNo" placeholder="请输入学号" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="学生姓名" prop="stuName">
                <el-input v-model="queryParams.stuName" placeholder="请输入学生姓名" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="岗位名称" prop="postName">
                <el-input v-model="queryParams.postName" placeholder="请输入岗位名称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="设岗部门" prop="deptName">
                <el-input v-model="queryParams.deptName" placeholder="请输入设岗部门" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="负责人姓名" prop="fzrName">
                <el-input v-model="queryParams.fzrName" placeholder="请输入负责人姓名" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-s-flag" size="mini"
                    @click="manyAssess('优秀')">批量优秀</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-finished" size="mini"
                    @click="manyAssess('良好')">批量良好</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-check" size="mini"
                    @click="manyAssess('合格')">批量合格</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="info" plain icon="el-icon-close" size="mini"
                    @click="manyAssess('不合格')">批量不合格</el-button>
            </el-col>
            <el-col :span="8">
                当月已填报（不含拒绝）/ 总学生岗位数:{{ money_stu_post }} / {{ all_stu_post }}
            </el-col>
        </el-row>

        <el-table v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" />
            <el-table-column label="学号" align="center" prop="stuNo" />
            <el-table-column label="姓名" align="center" prop="stuName" />
            <el-table-column label="性别" align="center" prop="gender" />
            <el-table-column label="学院" align="center" prop="stuDept" />
            <el-table-column label="岗位名称" align="center" prop="postName" />
            <el-table-column label="设岗部门" align="center" prop="deptName" />

            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                        @click="assessVClick(scope.row)">工作考核</el-button>
                    <el-button size="mini" type="text" icon="el-icon-money"
                        @click="moneyClick(scope.row)">结算月薪</el-button>
                    <el-button size="mini" type="text" icon="el-icon-view" @click="lookVClick(scope.row)">查看</el-button>
                    <el-button v-if="scope.row.workStatus == '是'" size="mini" type="text" icon="el-icon-close"
                        @click="doQuit(scope.row)">退岗</el-button>
                </template>
            </el-table-column>
        </el-table>



        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />

        <el-dialog title="工作考核" width="900px" :visible.sync="assessV" append-to-body>
            <el-select size="mini" v-model="assessForm.assess" placeholder="请选择月度考核">
                <el-option label="优秀" :value="'优秀'"></el-option>
                <el-option label="良好" :value="'良好'"></el-option>
                <el-option label="合格" :value="'合格'"></el-option>
                <el-option label="不合格" :value="'不合格'"></el-option>
            </el-select>
            <el-button type="success" plain size="mini" @click="doAssess">考核</el-button>
            <el-input v-model="assessForm.remark" size="mini" placeholder="备注(默认为空)" />

            <el-table :data="assess_list">
                <el-table-column label="#" align="center" prop="id" />
                <el-table-column label="学号" align="center" prop="stuNo" />
                <el-table-column label="姓名" align="center" prop="stuName" />
                <el-table-column label="岗位名称" align="center" prop="postName" />
                <el-table-column label="设岗部门" align="center" prop="deptName" />
                <el-table-column label="工作考核" align="center" prop="assess" />
                <el-table-column label="提交时间" align="center" prop="submitTime" width="180" />
                <el-table-column label="备注" align="center" prop="remark" width="180" />
            </el-table>

            <pagination v-show="assessTotal > 0" :total="assessTotal" :page.sync="assessQuery.pageNum"
                :limit.sync="assessQuery.pageSize" @pagination="getAssessList" />
        </el-dialog>



        <el-dialog title="查看" :visible.sync="lookV" append-to-body fullscreen>
            <el-form class="lookForm" size="mini" ref="auditForm" label-width="148px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="审核意见">
                            <el-radio-group disabled v-model="applyForm.zdlsCmt">
                                <el-radio :label="'通过'">通过</el-radio>
                                <el-radio :label="'不通过'">不通过</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="指导老师签章">
                            <img v-if="applyForm.zdlsSign" :src="baseurl + applyForm.zdlsSign" width="200px"
                                height="50px" class="avatar">
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <hr />
            <el-form class="lookForm" size="mini" ref="applyForm" label-width="148px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="身份证号">
                            <el-input readonly v-model="applyForm.idCard" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="农行卡号">
                            <el-input readonly v-model="applyForm.bankCard" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="开户行">
                            <el-input readonly v-model="applyForm.bankAddr" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="联系电话">
                            <el-input readonly v-model="applyForm.stuPhone" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="课余时间(单位：小时)">
                            <el-input readonly v-model="applyForm.canTime" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="家庭地址">
                            <el-input readonly v-model="applyForm.familyAddr" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="宿舍">
                            <el-input readonly v-model="applyForm.stuDorm" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="家庭经济情况">
                            <el-input readonly v-model="applyForm.familyCondition"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="曾获得资助">
                            <el-input readonly type="textarea" v-model="applyForm.helpHis" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="申请原因">
                            <el-input readonly type="textarea" v-model="applyForm.applyReason" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="申请附件">
                            <div v-if="!isEmpty(applyForm.applyMaterial)">
                                <div v-for="(v, i) in applyForm.applyMaterial.split(',')" :key="i">
                                    <a style="text-decoration: underline; color: blue;" :href="baseurl + v"
                                        :download="v.split('/').pop()">{{ v.split("/").pop() }}</a>
                                </div>
                            </div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="申请人签字">
                            <img v-if="applyForm.applySign" :src="baseurl + applyForm.applySign" width="200px"
                                height="50px" class="avatar">
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <hr />
            <el-form class="lookForm" size="mini" ref="lookForm" label-width="148px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="岗位名称" prop="postName">
                            <el-input v-model="lookForm.postName" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="设岗部门" prop="deptId">
                            <el-input v-model="lookForm.deptName" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="设岗人数" prop="postCount">
                            <el-input v-model="lookForm.postCount" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="负责人" prop="fzrName">
                            <el-input v-model="lookForm.fzrName" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="指导老师" prop="zdlsName">
                            <el-input v-model="lookForm.zdlsName" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="联系电话" prop="zdlsPhone">
                            <el-input v-model="lookForm.zdlsPhone" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="付酬方式">
                            <el-input value="按小时" disabled />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="付酬标准">
                            <el-input value="15.00" disabled />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="预计金额(元/月/人)" prop="willMoney">
                            <el-input v-model="lookForm.willMoney" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="预计金额合计(元/月)" prop="willMoneyTotal">
                            <el-input readonly v-model="lookForm.willMoneyTotal" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item label="岗位职责" prop="workNeed">
                            <el-input type="textarea" v-model="lookForm.workNeed" readonly />
                        </el-form-item>
                    </el-col>


                    <el-col :span="24">
                        <el-form-item label="技能要求" prop="skillNeed">
                            <el-input type="textarea" v-model="lookForm.skillNeed" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item label="每周工作时长" prop="weekTime">
                            <el-input v-model="lookForm.weekTime" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="校区" prop="campusName">
                            <el-input v-model="lookForm.campusName" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="16">
                        <el-form-item label="工作地点" prop="workAddr">
                            <el-input v-model="lookForm.workAddr" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="岗位类型" prop="postType">
                            <el-input v-model="lookForm.postType" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="备注" prop="remark">
                            <el-input v-model="lookForm.remark" readonly />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

        </el-dialog>

    </div>
</template>
<script>

import { listTeacherCanSelectPost as getList, doQuit } from "@/api/workstudy/stuPost";
import { stuGetPost } from "@/api/workstudy/post";

import { isEmpty, fullLoading } from "@/api/helpFunc";
import { getToken } from "@/utils/auth";

import { getOwnSign } from "@/api/workstudy/post";

import { listZdls, doAssess, manyAssess } from "@/api/workstudy/assess";

import { doApply, countUnMoney } from "@/api/workstudy/money";



export default {
    name: "workstudy-StuPost-ZdlsAll",
    dicts: ['qgzx_stu_post_status'],
    data() {
        return {
            isEmpty,
            loading: false,

            tableData: [],
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                postName: null
            },


            lookForm: {},
            applyForm: {},

            upload: {
                headers: { Authorization: "Bearer " + getToken() },
                // 上传的地址
                url: process.env.VUE_APP_BASE_API + "/common/upload"
            },
            baseurl: process.env.VUE_APP_BASE_API + "/",

            lookV: false,

            assessV: false,
            assess_list: [],
            assessQuery: {
                pageNum: 1,
                pageSize: 10,
                stuPostId: null
            },
            assessTotal: 0,
            assessForm: {
                stuPostId: null,
                assess: null,
                remark: null
            },

            selectedId: [],

            all_stu_post: 0,
            money_stu_post: 0
        }
    },
    created() {
        this.countUnMoney();
        this.getList();
    },
    methods: {
        async countUnMoney() {
            let res = await countUnMoney();
            if (res.code == 200) {
                let data = { ...res.data };
                this.all_stu_post = data.all_stu_post;
                this.money_stu_post = data.money_stu_post;
            }
        },
        async moneyClick(row) {
            console.log(row);
            let loading = fullLoading(this);
            let res = await getOwnSign();
            loading.close();
            if (res.code == 200) {
                let data = { ...res.data };
                if (isEmpty(data.signature)) {
                    this.$confirm('您的签名尚未上传', '提示', {
                        confirmButtonText: '点我前往',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.$router.push("/user/profile")
                    }).catch(() => {

                    });
                } else {
                    let sdata = {
                        applySign: data.signature,
                        stuPostId: row.id
                    }

                    this.$confirm('每月只能填报一次，您确定要结算吗', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(async () => {
                        let loading1 = fullLoading(this);
                        let res1 = await doApply(sdata);
                        loading1.close();
                        if (res1.code == 200) {
                            this.$message.success(res1.msg);
                        }
                    }).catch(() => {

                    });

                }
            }
        },
        manyAssess(assess) {
            if (isEmpty(this.selectedId)) {
                this.$message.info("请勾选记录");
                return;
            }

            this.$prompt('您确定要批量' + assess + "吗？下方可输入备注(默认为空)。", '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(async ({ value }) => {
                let sdata = [];
                this.selectedId.map(x => {
                    let temp = {
                        stuPostId: x,
                        assess: assess,
                        remark: value
                    };
                    sdata.push(temp);
                });

                let loading = fullLoading(this);
                let res = await manyAssess(sdata);
                loading.close();
                if (res.code == 200) {
                    this.$message.success(res.msg);
                }

            }).catch(() => {

            });
        },
        handleSelectionChange(val) {
            this.selectedId = val.map(x => x.id);
        },
        async doAssess() {
            let sdata = {
                ...this.assessForm
            };
            if (isEmpty(sdata.assess)) {
                this.$message.info("请选择月度考核");
                return;
            }

            let loading = fullLoading(this);
            let res = await doAssess(sdata);
            loading.close();
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.getAssessList();
            }
        },
        async assessVClick(row) {
            this.assess_list = [];
            this.assessQuery.stuPostId = null;
            this.assessForm.stuPostId = null;
            this.assessQuery.stuPostId = row.id;
            this.assessForm.stuPostId = row.id;
            await this.getAssessList();
            this.assessV = true;
        },
        async getAssessList() {
            let loading = fullLoading(this);
            let res = await listZdls(this.assessQuery);
            loading.close();
            if (res.code == 200) {
                this.assess_list = [...res.rows];
                this.assessTotal = res.total;
            }
        },

        doQuit(row) {
            let sdata = {
                id: row.id
            }
            this.$confirm('您确定要将' + row.stuName + '同学退岗吗，此操作不可逆, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                let loading = fullLoading(this);
                let res = await doQuit(sdata);
                loading.close();
                if (res.code == 200) {
                    this.$message.success(res.msg);
                    this.getList();
                }
            }).catch(() => {

            });
        },
        async lookVClick(row) {
            this.applyForm = {};
            this.lookForm = {};
            this.applyForm = { ...row };
            let loading = fullLoading(this);
            let res = await stuGetPost(row.postId);
            loading.close();
            if (res.code == 200) {
                this.lookForm = { ...res.data };
                this.lookForm.deptName = row.deptName;
                this.lookForm.zdlsName = row.zdlsName; //指导老师姓名

                this.lookV = true;
            }
        },


        async getList() {
            this.loading = true;
            let res = await getList(this.queryParams);
            this.loading = false;
            if (res.code == 200) {
                this.tableData = [...res.rows];
                this.total = res.total;
            }
        },
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
    }
}



</script>


<style scoped lang="scss">
.lookForm {
    .el-form-item {
        margin-bottom: 5px;
    }
}
</style>